<html>
<head>
<title>BusinessData Services</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="services.css"/>
</head>
<body>

<h1>Smart Callsign Search Services</h1>
<div class="hostInfo">
<form action="">
<div>
<label for="scheme">Transport</label><select name="scheme" id="scheme">
<option value="http://">HTTP</option>
<option value="https://">HTTPS</option></select>
</div>
<div>
<label for="host">Host</label><select name="host" id="host"></select>
</div>
</div>

</form>
</div>
<div class="services">
<div class="serviceInfo">


<form id="actionform" target="_blank">
<div><label>Request:</label>
<textarea name="xml" id="xml" style="width:800px;height:250px;">
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:certificateCallsignSearchCriteria xmlns:ns2="http://g2b.fmit.co.nz/smart/rest">
<vesselName>hms</vesselName>
</ns2:certificateCallsignSearchCriteria>
</textarea>
</div>
<div><label>Response:</label>
<textarea name="response" id="response" style="width:800px;height:250px;"></textarea>
<div>
<button onclick="dosubmit(this.form);return false;">Submit</button>
</div>
</form>
</div>
</div>

<script type="text/javascript">

var topWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                   .getInterface(Components.interfaces.nsIWebNavigation)
                   .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                   .rootTreeItem
                   .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                   .getInterface(Components.interfaces.nsIDOMWindow);
var BusinessDataChrome = topWindow.BusinessDataChrome; 
var baseUrl = '/data/app/ws/rest/rsm/certificatesAndCallsigns/search/v1.0';
function dosubmit(frm){
   var $host = $('#host');
   var $scheme = $('#scheme option:selected');
   var url = baseUrl;
   if ($host.val() == 'localhost'){
        url = url.replace(/\/data\/app\/ws/, ':8080/fmit-g2b-webservice');
   }
   url = $scheme.val()+$host.val()+url;
   var req = new XMLHttpRequest();
   req.open('POST', url, true);
   req.setRequestHeader("Content-Type", "application/xml");
   req.onreadystatechange = function (aEvt) {
	  if (req.readyState == 4) {	   
	      $('#response').val(req.responseText);	      
	  }
	};
   req.send($('#xml').val());

}
$(function(){
  BusinessDataChrome.initAccessInfo();
  var sel = $('#host').get(0);
  for(key in BusinessDataChrome.accessInfo){
    var op = new Option(key, key,false);
    sel.options.add(op);
  }
  
});
</script>
</body>
</html>
